﻿// -----------------------------------------------------------------------
// <copyright file="FileListItemTemplateSelector.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace TouchExplorer.Controls
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Controls;
using System.Windows;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class FileListItemTemplateSelector : DataTemplateSelector
    {
        public DataTemplate ListTemplate { get; set; }
        public DataTemplate TilesTemplate { get; set; }

        public ItemsPanelTemplate ListPanelTemplate { get; set; }
        public ItemsPanelTemplate TilesPanelTemplate { get; set; }

        private ExplorerViewModel Model
        {
            get
            {
                return _parentList.DataContext as ExplorerViewModel;
            }
        }

        private ListBox _parentList;

        public FileListItemTemplateSelector()
        {
            
        }

        public FileListItemTemplateSelector(ListBox lst)
        {
            _parentList = lst;            
        }

        public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            if (_parentList == null)
                return ListTemplate;

            var display = Model.Display;
            
            if (display == ExplorerViewModel.DisplayType.Tiles)
            {
                _parentList.ItemsPanel = TilesPanelTemplate; 
                return TilesTemplate;
            }

            _parentList.ItemsPanel = ListPanelTemplate;
            return ListTemplate;
        }
    }
}
